package com.example.accountbook;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class AccountTrafficFragment extends Fragment {

    private RecyclerView rvAccount;
    private AccountItemAdapter adapter;
    private List<CostBean>list;

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.account_list,container,false);
        rvAccount = view.findViewById(R.id.rv_account);

        initData();

        adapter = new AccountItemAdapter(this.getContext(),list);
        LinearLayoutManager layout = new LinearLayoutManager(this.getContext());

        rvAccount.setLayoutManager(layout);//设置布局管理器
        rvAccount.setAdapter(adapter);//设置是适配器
        rvAccount.setItemAnimator(new DefaultItemAnimator());//设置Item增加，移除动画
        rvAccount.addItemDecoration(new DividerItemDecoration(this.getContext(),DividerItemDecoration.VERTICAL));//添加分割线

        return view;
    }

    public void initData() {

        list = new ArrayList<>();

        for (int i = 0; i < 5; i++) {
            CostBean bean = new CostBean();
            bean.setType("交通");
            bean.setTitle("周末出行");
            bean.setExplain("行程车费");
            bean.setTime("2018-11-27");
            bean.setMoney(30);
            list.add(bean);
        }
    }
}
